<?php

namespace Bean\Flow\PostsFlow\Item;

class UserPost extends \Bean\Flow\PostsFlow\Item {

	private $_data;
	private $_user;
	
	public function __construct( $data, \Bean\Flow\PostsFlow $flow ) {
		parent::__construct( $data, $flow );
		$this->_data = $data;
	}
	
	public function isCommentable( \Bean\User $user = null ) {
		$user = _u( $user );
		if( !$user ) {
			return false;
		}
		return $user->getUserId() == $this->getUserId()
			|| $user->isContact( $this->getUser() );
	}
	
	public function isLikable( \Bean\User $user = null ) {
		$user = _u( $user );
		if( !$user ) {
			return false;
		}
		return $user->getUserId() == $this->getUserId()
			|| $user->isContact( $this->getUser() );
	}
	
	public function getUserId() {
		return $this->_data['user_id'];
	}
	
	public function getUser() {
		if( $this->_user === null ) {
			$this->_user = $this->_user = \Bean\User::get( $this->getUserId() );
		}
		return $this->_user;
	}
}
